using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Recruiters_profile : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            connectionString =
           WebConfigurationManager.ConnectionStrings[
           "RecruitVietnam"].ConnectionString;
            if (Session.Contents["rcuserid"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {

                if (!IsPostBack)
                {
                    LoadDataForDropDownList();
                    EditProfile();
                }

            }
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
    void LoadDataForDropDownList()
    {
        DropDownListHelper helper =
                new DropDownListHelper();
        string selectQuery =
        "Select * from tblProvinces;";
        Common cls = new Common(connectionString);
        DataTable dataTable = cls.GetDataTable(selectQuery);        
        helper.FillDataTableToDropDownList(
        dataTable, ddlProvince, 
        "ProvinceName", "ProvinceID", "");
    }

    void EditProfile()
    {
        SqlServerProvider cls =
        new SqlServerProvider();
        cls.ConnectionString = connectionString;
        cls.CommandText =
        "select * from vwRCProfile" +
        " where RecruiterID=@RecruiterID";
        cls.ParameterCollection =
        new string[1] { "@RecruiterID" };
        cls.ValueCollection = new
        string[1] { Session["rcuserid"].ToString() };
        DataRow dataRow =
        cls.GetDataRow();
        if (dataRow[1].ToString() == "")
            btnNext.Text = "Save";
        else
        {
            btnNext.Text = "Update";
            txtAddress.Text = dataRow[1].ToString();
            txtContactName.Text = dataRow[2].ToString();    
            txtTel.Text = dataRow[3].ToString();
            txtFax.Text = dataRow[4].ToString();
            ddlProvince.SelectedValue = dataRow[5].ToString();
            txtCity.Text = dataRow[6].ToString();
            ddlCountry.SelectedValue = dataRow[7].ToString();
                    
            txtDOE.Text = dataRow[8].ToString();                         
            
        }

    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        try
        {
            RecruitVietnam cls = new RecruitVietnam();
            cls.ConnectionString = connectionString;
            if (!cls.UpdateCompany(Convert.ToString(
                Session.Contents["rcuserid"]),
                txtContactName.Text,
                txtAddress.Text,
                txtCity.Text,
                txtTel.Text,
                txtFax.Text, 
                ddlCountry.SelectedValue,
                ddlProvince.SelectedValue,
                txtDOE.Text))
                literalError.Text = "Error: " + cls.ErrorMessage;
            else                
                
                Response.Redirect("myaccount.aspx");
               
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
}
